<template>
  <div>
    <el-row>
      <el-col :span="6">
        <el-cascader
          v-model="value"
          placeholder="请选择原来的学院班级"
          :options="options"
          :props="{
            label: 'name',
            value: 'id',
          }"
          @change="chioce"
        ></el-cascader>
      </el-col>
      <el-col :span="6">
        <el-cascader
          v-model="value1"
          placeholder="请选择新的学院班级"
          :options="options"
          :props="{
            label: 'name',
            value: 'id',
          }"
        ></el-cascader>
      </el-col>
    </el-row>
    <!-- 穿梭框 -->
    <el-transfer
      v-model="transvalue"
      :props="{
        key: 'id',
        label: 'name',
      }"
      @change="editClass"
      :data="data"
    >
    </el-transfer>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import {
  getCollege_Class,
  getStudentsByclass,
  raiseDropClasses,
} from '../../api/students'
export default {
  data() {
    return {
      options: [],
      value: '',
      value1: '',
      transvalue: '',
      changetransvalue: '',
      data: [],
      changeClasss:{
        newClassId:'',
        studentsId:[],
      },
    }
  },
  created() {
    this.getCollegeClass()
  },
  methods: {
    // 获取学院和班级信息树
    async getCollegeClass() {
      var res = await getCollege_Class()
      this.options = res.data
      this.$message.success('获取数据成功')
    },
    async chioce() {
      if (this.value) {
        console.log(this.value[1])
        var res = await getStudentsByclass(this.value[1])
        console.log(res.data)
        this.data = res.data
      } else {
        this.$message.warning('请选择班级')
      }
    },
    async editClass() {
      if (this.value1) {
        var ss = ''
        if (this.changetransvalue == '') {
          ss = this.transvalue
        } else {
          var lengths = this.changetransvalue.length
          ss = this.transvalue.substring(lengths)
        }
        this.changetransvalue = this.transvalue
        var res = await raiseDropClasses(this.value1[1],ss.split(','))
        console.log(res)
        if (res.status==200){
          Message.success(res.message)
          window.location.reload()
        }
      }
      else{
        Message.warning('请选择新的班级')
        this.transvalue=''
      }
    },
  },
}
</script>

<style>
</style>